﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.Sales
{
    public partial class PartyesDetail : Form
    {
        Int32 _party;
        public PartyesDetail(Int32 party)
        {
            _party = party;
            InitializeComponent();
        }

        private void PartyesDetail_Load(object sender, EventArgs e)
        {
            DataSets.UtilTableAdapters.PartyDefaultTableAdapter adapter = new DIProject.DataSets.UtilTableAdapters.PartyDefaultTableAdapter();
            DataSets.Util.PartyDefaultDataTable dt = adapter.GetData(_party);
            if (dt.Count < 1)
            {
                MessageBox.Show("Партия не найдена");
                this.Close();
            }
            DataSets.Util.PartyDefaultRow row = dt.Rows[0] as DataSets.Util.PartyDefaultRow;
            lblSeller.Text = row.Name;
            lblinnerId.Text = row.docId.ToString();// row.DocNumber;             
           // lblNumDoc.Text = row.ContragentDocNumber; 
            lblInnerDate.Text = row.DocDate.ToString("d");
            if (!row.IsContragentDocDateNull())
            {                
                lblSellerDate.Text = row.ContragentDocDate.ToString("d");
            }
            
            if (!row.IsContragentDocNumberNull())
                llGoToNcld.Text = row.ContragentDocNumber;
            else
                llGoToNcld.Text = "Неизвестно";
            llGoToNcld.Tag = row.docId;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void llGoToNcld_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (string.IsNullOrEmpty(lblinnerId.Text))
                return;
            Int32 iid = Convert.ToInt32(lblinnerId.Text);
            Int32 dId = Data.Party.GetParentId(iid);
          //  Int32 dId = Data.Party.GetPartyDocId(iid);
            if (dId == 0)
                // return;
                dId = iid;
            Int32 cId = Data.Party.GetContragentIdFromDocument(dId);
            Int32 depId = Data.Party.GetDepartmentIdFromDocument(dId);
            if (cId == -1)
                return;
            ReceptionGoods.WaybillsImportList w = new DIProject.ReceptionGoods.WaybillsImportList();
            w.MdiParent = this.MdiParent;
            w.Show();
            w.cbContragents.ComboBox.SelectedValue = cId;
            w.ddlDepartment.ComboBox.SelectedValue = depId;
            w.cbContragents_SelectedIndexChanged1(w.cbContragents, EventArgs.Empty);
            w.lbNaklList.SelectedValue = dId;
            w.lbNaklList_DoubleClick(w.lbNaklList, EventArgs.Empty);
            this.Close();
        }
    }
}